<template>
  <div>
    <y-header></y-header>
    <div class="person_body clearfix">
      <div class="person_content">
        <ul class="person_title clearfix">
          <li>{{this.$route.query.title}}</li>
        </ul>
        <div class="person_info ">
          <table class="table ">
            <thead>
              <tr>
                <th style="width:200px;">角色</th>
                <th>内容</th>             
                <th>回复时间</th>                             
                <th>序号</th>            
              </tr>
            </thead>
            <tbody>
                  <tr v-for="(item, index) in questionDetail" :key="item.id">               
                    <td v-if="item.type == 1">老师说</td> 
                    <td v-if="item.type == 2">学生说</td>  
                    <td class="name">{{item.content}}</td>                 
                    <td class="name">{{item.gmtCreate}}</td> 
                    <td>{{index + 1}}</td>                                               
                  </tr>         
                  <tr>               
                    <td class="name"><input type="text" v-model="obj.content" class="form_input" placeholder="输入回复"></td>
                    <td class="operate">
                       <button class="solid_btn b_red" @click="addPraxis" :disabled="solidBtn">发布</button> 
                    </td>
                  </tr>                          
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <y-footer></y-footer>
  </div>
</template>
<script>
import YHeader from '~/components/common/Header'
import YFooter from '~/components/common/Footer'
import {answerDoubtList,answerDoubtViewDetail,answerDoubtSaveTitleForStudent,answerDoubtSaveReply} from '~/api/account/courseOtherFile'
export default {
  data () {
    return {
      load: false,
      tab: 1,
      num: 1,
      list: [],
      solidBtn: false, 
      questionDetail:[], 
      sort: 0,
       obj: {
        content: []
      }
    }
  },
  computed: {
    isUp () {
      if (this.docUrl) {
        return false
      } else {
        return true
      }
    }
  },
  methods: {
    
      openDetail() {
        answerDoubtViewDetail({answerDoubtThemeId:this.$route.query.themeId}).then(res => {
                res = res.data;
                console.log(res.data);
                if (res.code === 200 && res.data.list.length > 0 ) {
                  this.questionDetail = res.data.list;
               
                } else {
                  if (res.code >= 300 && res.code < 400) {
                    this.$msgBox({
                      content: res.msg,
                      isShowCancelBtn: false
                    }).then(() => {
                      this.$store.dispatch('REDIRECT_LOGIN', result.code)
                    }).catch(() => {
                      this.$store.dispatch('REDIRECT_LOGIN', result.code)
                    })
                  } else {               
                    this.$msgBox({
                      content: '暂无内容',
                      isShowCancelBtn: false
                    }).catch(() => {})
                  }
                }     
              }).catch(() => {
                this.solidBtn = false;
                this.$msgBox({
                  content: '暂无内容',
                  isShowCancelBtn: false
                });
                  this.obj ='';  
              })
     },

    addPraxis () {     
  
      if (!this.obj.content) {
        
        this.$msgBox({
          content: '请输入内容',
          isShowCancelBtn: false
        })
        return
      }
    
      this.solidBtn = true;
      answerDoubtSaveReply(
       
        {
          answerDoubtThemeId:this.$route.query.themeId,
          content:this.obj.content,
          type:this.$route.query.userType

        }).then(res => {
        res = res.data;
        this.solidBtn = false;
        if (res.code === 200) {
          this.questionDetail.push(res.data);
          this.num = this.list.length + 1;
          this.obj.content ='';  
        } else {
          if (res.code >= 300 && res.code < 400) {
            this.$msgBox({
              content: res.msg,
              isShowCancelBtn: false
            }).then(() => {
              this.$store.dispatch('REDIRECT_LOGIN', result.code)
            }).catch(() => {
              this.$store.dispatch('REDIRECT_LOGIN', result.code)
            })
          } else {
            this.$msgBox({
              content: res.msg,
              isShowCancelBtn: false
            }).catch(() => {})
          }
        }     
      }).catch(() => {
        this.solidBtn = false;
        this.$msgBox({
          content: '保存成功',
          isShowCancelBtn: false
        });
         
      })
     },
   
  },
  created () {
      this.openDetail();
  },
  components: {
    YHeader,
    YFooter,
  }
}
</script>
<style lang="scss" rel="stylesheet/scss">
@import '~/assets/css/account.scss';
  .person_body {
    width: 1200px;
    margin: 30px auto 0;
    min-height: 1000px;
    .upload_com {
      .solid_btn {
        display: inline-block;
        height: 25px;
        line-height: 22px;
        background: #fff;
        border-color: #ddd;
        color: #999;
        outline: none;
        &:hover {
          color: #D51423;
          border-color: #D51423;
        }
      }
    }
  }
  .person_content {
    width: 1012px;
    float: right;
    background: #fff;
    border-radius: 6px;
  }
  .person_title {
    border-bottom: 1px solid rgb(242, 242, 242);
    li {
      color: #D51423;
      float: left;
      line-height: 60px;
      padding: 0 30px;
      border-bottom: 2px solid #D51423;
      font-size: 14px;
    }
  }
  .person_info {
    padding-bottom: 40px;
  }
  .name{
    .form_input{
      margin: 10px 0;
      height: 34px;
      border: 1px solid #e7e7e7;
      width: 278px;
      text-indent: 1em;
    }
  }
  .cont_btn {
    width: 280px;
    display: block;
    margin:20px auto 0;
  }

   .table td.name {
    text-align: center;
  }
  .table th {
    line-height: 36px;
    color: #333;
    background-color: #ffffff;
    width: 200px;
}
</style>
